package org.example.demo.dao;

import org.example.demo.entity.User;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class UserDao {
    private static final Map<Integer, User> userMap = new HashMap<>();
    private static Integer size = 5;

    static {
        userMap.put(1, new User(1, "zs", 20, "男"));
        userMap.put(2, new User(2, "ls", 21, "女"));
        userMap.put(3, new User(3, "ww", 22, "男"));
        userMap.put(4, new User(4, "zl", 23, "女"));
    }

    public Collection<User> getAllUser() {
        return userMap.values();
    }

    public User getUserById(Integer id) {
        return userMap.get(id);
    }

    public void add(User user) {
        userMap.put(size, user);
        size += 1;
    }

    public void update(User user) {
        userMap.put(user.getId(), user);
    }

    public void delete(Integer id) {
        userMap.remove(id);
    }
}
